﻿using UnityEngine;
using System.Collections;

public class MessageToView : MessageViewBase
{
    public MessageToView()
    {
        base._classType = 1;
    }

    public override void Handle()
    {
        switch (_type)
        {
            case MessageViewType.MTV_single_move:
                SingleProcessMoveCharacter((Character)_factor1, (MoveDirection)_factor2, (float)_factor3);
                break;
            case MessageViewType.MTV_single_gunbarrelRotate:
                SingleProcessRotateGunBarrel((Character)_factor1, (int)_factor2, (float)_factor3);
                break;
            case MessageViewType.MTV_single_fire:
                SingleProcessFire((Character)_factor1);
                break;
        }
    }

    private void SingleProcessMoveCharacter(Character gameChar, MoveDirection dir, float fDT)
    {
        GamePlayScene playScene = GameCommon.GetPlayScene();
        playScene._CharacterMovement.HorizonMove(gameChar, dir, fDT);
    }

    private void SingleProcessRotateGunBarrel(Character gameChar, int upDown, float fDT)
    {
        gameChar.UpdownGunBarrel(upDown, fDT);
    }

    private void SingleProcessFire(Character gameChar)
    {
        GameObject obj = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/CannonBall"), new Vector3(gameChar.transform.localPosition.x, gameChar.transform.localPosition.y + 40.0f, gameChar.transform.localPosition.z), gameChar.transform.localRotation );

        GamePlayScene playScene = GameCommon.GetPlayScene();

        playScene.SetCannonBall(obj.GetComponent<CannonBall>());
        playScene._inGameStateMgr.ChangeState(InGameStateManager.StateType.SingleFlyCannonBall);
    }
    
}